package com.estar.integaration.Util;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.NumberUtils;
import org.apache.poi.ss.usermodel.DateUtil;

/**
 * Author: YJL
 * Date: 2022/2/17 18:34
 **/
public class DateConverter implements Converter<String> {

  @Override
  public Class supportJavaTypeKey() {
    return null;
  }

  @Override
  public CellDataTypeEnum supportExcelTypeKey() {
    return null;
  }

  @Override
  public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
    if(cellData.getDataFormat() != null){
     if(cellData.getDataFormatString() == null){
       return DateUtils.format(DateUtil.getJavaDate(cellData.getNumberValue().doubleValue(),
           globalConfiguration.getUse1904windowing(),null),DateUtils.DATE_FORMAT_10);
     }else {
       return NumberUtils.format(cellData.getNumberValue(),contentProperty);
     }
    }
    return null;
  }

  @Override
  public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
    return null;
  }


}
